#!/usr/local/bin/perl
use utf8;


print "Content-type: text/html charset=utf-8\n\n";
print "<html>";
print "<HEAD><TITLE><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></TITLE></HEAD>\n";

use DBI;

# Connect To Database
$database = "frcc_conference";
$username = "frcc_admin";
$password = "frcc1234";
$hostname = "localhost";
$db = DBI->connect("DBI:mysql:$database:$hostname", $username, $password);

#if(!$db = DBI->connect("DBI:mysql:$database:$hostname", $username, $password))
#     print "Connection unsuccessful. Please check your login credentials. ".$DBI::errstr;
# Execute a Query

$query = $db->do( "SET character_set_client ='utf8'");
$query = $db->do( "SET character_set_connection='utf8'");
$query = $db->do( "SET character_set_results='utf8'");

$query = $db->prepare("SELECT regid, cname, first_name, last_name FROM registrant");
$query->execute;

# How many rows in result?
$numrows = $query->rows;

while(my $ref = $query->fetchrow_hashref()) {
    print "User: $ref->{'regid'}";
    print "Country: $ref->{'cname'}";
    print "----------\n";
}


# Display Results
#while (@array = $query->fetchrow_array) {
#($field1, $field2, $field3, $field4) = @array;
#print "field1 = $field1, field2 = $field2, field3 = $field3, field4=$field4";
#}


# Cleaning Up
$query->finish;
$db->disconnect;

exit(0);
